package com.clouddisk.file.observer.impl;

import com.clouddisk.common.util.RedisUtil;
import com.clouddisk.file.observer.FileOperationEvent;
import com.clouddisk.file.observer.FileOperationListener;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class StatisticsFileOperationListener implements FileOperationListener {

    private final RedisUtil redisUtil;
    private static final String FILE_OPERATION_COUNT_KEY = "file:operation:count:";
    private static final String USER_OPERATION_COUNT_KEY = "user:operation:count:";

    @Override
    public void onFileOperation(FileOperationEvent event) {
        // 统计文件操作次数
        String fileKey = FILE_OPERATION_COUNT_KEY + event.getOperation();
        redisUtil.increment(fileKey);

        // 统计用户操作次数
        String userKey = USER_OPERATION_COUNT_KEY + event.getUserId() + ":" + event.getOperation();
        redisUtil.increment(userKey);
    }
} 